package com.codergd.gra.dao;

import com.codergd.gra.bean.Job;
import com.codergd.gra.vo.JobCom;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.List;

@Repository
public interface JobDao {
    @Insert("insert into job(job,validTime,experience,description,number,sallow,salhi,wit,com)"
            + "values (#{job},#{validTime},#{experience},#{description},#{number},#{sallow},#{salhi},#{wit},#{com})")
    public int insertJob(Job job);

    @Select("select wit from fuzu where com = #{com}")
    public Integer selectWitByCom(int com);

    @Select("select * from job where com = #{com} order by wit desc")
    public List<Job> getJob(int com);

    @Select("select * from job where id = #{id}")
    public Job getJobInfo(int id);

    //获取职位信息根据id
    @Select("select * from job where id = #{id}")
    public Job getJobById(int id);

    //模糊获取职位
    @Select("select * from job j,com c " +
            "where j.com = c.id and (j.job like concat('%','${str}','%') or c.comname like concat('%','${str}','%') ) order by j.wit desc")
    public List<JobCom> getJobByStr(String str);

    //获取职位信息根据根绝意愿
    @Select("<script>" +
            "select * from job as j,com as c where j.com = c.id and " +
            "(sallow >= #{sal} and job like concat('%','${job}','%') " +
            "<if test=\"#{sal1} != null and #{job1} != null \"> or sallow >= #{sal1} and job like concat('%','${job1}','%')</if>) and " +
            "c.address like concat('%','${address}','%')" +
            "order by wit desc </script>")
    public List<JobCom> getJobByUser(int sal, String job,int sal1, String job1,String address);

    //修改职位信息
    @Update("update job set job = #{job},validTime = #{validTime},experience = #{experience}," +
            "description = #{description},number = #{number},sallow = #{sallow},salhi = #{salhi} where id = #{id}")
    public int updaeJob(Job job);

    //删除职位信息
    @Update("delete from job where id = #{id}")
    public int deleteJob(int id);

    //查询原来的权重
    @Select("select wit from job where id = #{id}")
    public int selectWit(int id);

    //修改支付后的权重
    @Update("update job set wit = #{wit} where id = #{id}")
    public int updateWit(int id,int wit);

    //查询权重不为0的职位
    // @Select("select * from job j,com c " +
    //         "where j.com = c.id and j.wit != 0 order by j.wit desc")
    @Select("select * from job j,com c " +
            "where j.com = c.id order by j.wit desc")
    public List<JobCom> getJobByWit();

}
